package org.lalib.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

@Service("applicationContextUtil")
public class ApplicationContextUtil implements ApplicationContextAware {

	private static ApplicationContext ctx;

	public static ApplicationContext getApplicationContext() {
		return ctx;
	}

	@Override
	@SuppressWarnings("static-access")
	public void setApplicationContext(ApplicationContext context) throws BeansException {
		this.ctx = context;
	}

	public static Object getNewInstrance(String name) {
		return getApplicationContext().getBean(name);
	}
}